package com.cfl.ticketmodule.controller;

import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cfl.model.Ticket;
import com.cfl.ticketmodule.service.TicketService;


@Controller
public class TicketController {

	@Autowired
	private TicketService ticketService;
	
	@RequestMapping("find_my_tickets")
	@ResponseBody
	public Object findMyTickets(String uid, Integer page)
	{
		try {
			if(StringUtils.isBlank(uid))
			{
				return null;
			}
			if(page == null)
			{
				page = 0;
			}
			ArrayList<Ticket> tickets = ticketService.findMyTickets(uid, page);
			return tickets;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("add_ticket")
	@ResponseBody
	public Boolean addTicket(Ticket ticket)
	{
		try {
			ticketService.addTicket(ticket);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}
